const config = require('../src/utils/config')

const { apiPrefix } = config

let statisticsOfDialogue = []

for (let i = 0; i < 10; i++) {
  let id = i + 1
  statisticsOfDialogue.push({
    id: id,
    avatar: i % 10 === 0 ? 'http://wx.qlogo.cn/mmhead/ver_1/4P7EyyQ4ibNptL57TN10jZeWFV2oGfnCHOlvFia0Ejy1ycJgxdcdIa9cgwVIQYhDdvVnC816elZFW84xTqiafKvjbzVKGO9dzbN6UMKwTn1X0U/132' : '',
    wxId: '重复好友微号' + id,
    employee: {
      name: '归属员工' + id,
      department: {
        name: '归属部门' + id
      }
    },
    contactCount: id,
    twoWeekData: {
      "1": id,
      "2": id,
      "3": id,
      "4": id,
      "5": id,
      "6": id,
      "7": id,
      "8": id,
      "9": id,
      "10": id,
      "11": id,
      "12": id,
      "13": id,
      "14": id
    }
  })
}

const statisticalDiagram = [
  {
    item: "文本",
    count: 0
  },
  {
    item: "图片",
    count: 0
  },
  {
    item: "语音",
    count: 0
  },
  {
    item: "名片",
    count: 0
  },
  {
    item: "位置",
    count: 9
  },
  {
    item: "语音位置",
    count: 9
  },
  {
    item: "视频位置",
    count: 9
  },
  {
    item: "通知消息",
    count: 9
  },
  {
    item: "转账",
    count: 9
  },
  {
    item: "红包",
    count: 9
  },
  {
    item: "文件",
    count: 9
  },
  {
    item: "其他",
    count: 10
  }
]

module.exports = {
  [`GET ${apiPrefix}/statisticsOfDialogue/query`](req, res) {
    const { query } = req
    let { size, current, ...other } = query
    size = size || 10
    current = current || 1

    let newData = statisticsOfDialogue
    for (let key in other) {
      if ({}.hasOwnProperty.call(other, key)) {
        newData = newData.filter((item) => {
          if ({}.hasOwnProperty.call(item, key)) {
            return String(item[key]).trim().indexOf(decodeURI(other[key]).trim()) > -1
          }
          return true
        })
      }
    }

    res.status(200).json({
      code: 0,
      message: "successed",
      data: {
        records: newData,
        total: newData.length,
      },
    })
  },

  [`GET ${apiPrefix}/statisticsOfDialogue/queryStatisticalDiagram`](req, res) {
    const { query } = req
    let { size, current, ...other } = query
    size = size || 10
    current = current || 1

    res.status(200).json({
      code: 0,
      message: "successed",
      data: {
        records: statisticalDiagram,
      },
    })
  }
}
